package com.example.SearchZB;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.BaiduMapOptions;
import com.baidu.mapapi.map.MapStatus;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.model.LatLng;
import com.example.SeachZB.R;

/**
 * Created by Administrator on 2014/11/27.
 */
public class PoiListActivity extends Activity{

    private Button btn_range;
    private static final String LTAG = PoiListActivity.class.getSimpleName();
    private MapView mapView;
    private BaiduMap baiduMap;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_poilist);

        Intent intent = getIntent();
        if (intent.hasExtra("34.230878") && intent.hasExtra("108.889583")) {
            Bundle b = intent.getExtras();
            LatLng p = new LatLng(b.getDouble("108.889583"), b.getDouble("34.230878"));
            mapView = new MapView(this,
                    new BaiduMapOptions().mapStatus(new MapStatus.Builder()
                            .target(p).build()));
        } else {
            mapView = new MapView(this, new BaiduMapOptions());
        }
        setContentView(mapView);
        baiduMap = mapView.getMap();

        btn_range = (Button) findViewById(R.id.btn_range);
        btn_range.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                final String[] items = getResources().getStringArray(R.array.item);
                new AlertDialog.Builder(PoiListActivity.this)
                        .setTitle("选择范围")
                        .setIcon(android.R.drawable.ic_dialog_info)
                        .setSingleChoiceItems(items, 0,
                                new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int which) {
                                        btn_range.setText("范围："+ items[which]);
                                        dialog.dismiss();
                                    }
                                }
                        )
                        .setNegativeButton("取消", null)
                        .show();
            }
        });
    }

    @Override
    protected void onPause() {
        super.onPause();
        mapView.onPause();
    }

    @Override
    protected void onResume() {
        super.onResume();
        mapView.onResume();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mapView.onDestroy();
    }
}
